<!--
 * @FileDescription: 用户信息修改（仅管理员可见）
 * @Author: 周沿江
 * @Date: 2021/6/25
 * @LastEditors: 周沿江
 -->
<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 用户信息管理
                </el-breadcrumb-item>
                <el-breadcrumb-item> 用户信息修改</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-card>
            <div class="form-box" >

              <el-form :model="admin_info">
                <el-form-item label="用户名" label-width="120px">
                  <el-input v-model="admin_info.username" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="密码" label-width="120px">
                  <el-input v-model="admin_info.password" disabled autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="手机号码" label-width="120px">
                  <el-input v-model="admin_info.phone" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="账号创建时间" label-width="120px">
                  <el-input v-model="admin_info.createTime"  autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="最后登录时间" label-width="120px">
                  <el-input v-model="admin_info.lastLoginTime"  autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item  style="margin-top: 3%" >
                  <el-button type="primary" @click="onSubmit" style="margin-left: 10%">更改用户</el-button>

                    <el-button style="margin-left: 10%" @click="onReset" type="warning" >重置设置</el-button>

                </el-form-item>
              </el-form>
            </div>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: 'baseform',
        data() {
            return {
                admin_info: {
                },
            };
        },
      created() {
        this.init();
      },
        methods: {
          /**
           * 初始化用户数据
           */
            init(){
              var admin= this.$route.params.admin_info;
              if(admin != undefined){
                this.admin_info = this.$route.params.admin_info;
                console.log(this.admin_info)
              }
            },
          /**
           * 用户提交修改数据
           * @returns {Promise<void>}
           */
            async onSubmit() {
                var a = this.admin_info;
                delete a.user_status;
                delete a.user_status_descri;
              console.log(a);
                var data =  await this.$http.post('/user/updateByName',a);
                if(data=="success"){                this.$message.success('更改成功！');}
                else{                this.$message.error('更改失败！');}
            },
          /**
           * 返回句柄
           */
          onReset(){
            this.$router.go(-1);
          }
        }
    };
</script>

<style scoped>
.el-form-item{
  font-family: "PingFang SC";
  font-weight: bolder;
}
</style>